<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ishowshao
 * Date: 11-10-26
 * Time: 下午4:04
 * To change this template use File | Settings | File Templates.
 */
include_once 'paperblog.php';
checkLogin();
$categorys = getCategorys();
$tags = getTags();
$settings = getSettings();
if (isset($_GET['action']) && isset($_GET['id'])) {
    $action = $_GET['action'];
    $id = $_GET['id'];
    if ($action === 'edit') {
        $post = getPostById($id);
    } elseif ($action === 'delete') {

    } else {
        exit('action not found');
    }
}
?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>编辑文章</title>
    <link href="resources/css/common.css" rel="stylesheet" />
    <script src="<?php echo $settings['base'] ?>/admin/resources/kindeditor/kindeditor.js"></script>
    <script src="<?php echo $settings['base'] ?>/admin/resources/kindeditor/lang/zh_CN.js"></script>
    <script>
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('#content');
        });
    </script>
</head>
<body>
    <form action="action/save.action.php" method="POST" class="common-form">
        <div>
            <label for="url">URL</label>
            <input type="text" id="url" style="width: 300px;" disabled="disabled" value="<?php echo $post['url'] ?>" /><span class="tips">用于命名生成的HTML文件</span>
            <input type="hidden" name="url" value="<?php echo $post['url'] ?>" />
        </div>
        <div>
            <label for="title">标题</label>
            <input type="text" name="title" id="title" style="width: 300px;" value="<?php echo $post['title'] ?>" />
        </div>
        <div>
            <label for="category">分类</label>
            <select name="category" id="category">
                <?php
                foreach ($categorys as $id => $category) {
                    $selected = '';
                    if ($post['category'] == $id) {
                        $selected = ' selected="selected"';
                    }
                ?>
                <option value="<?php echo $id ?>"<?php echo $selected ?>><?php echo $category['name'] ?></option>
                <?php
                }
                ?>
            </select>
        </div>
        <div>
            <label for="tags">标签</label>
            <input type="text" name="tags" id="tags" style="width: 300px;" value="<?php echo implode(',', $post['tag']) ?>" /><span class="tips">请用英文逗号分割</span>
        </div>
        <div>
            <label for="content" style="display: none;">内容</label>
            <textarea id="content" name="content" style="width: 720px; height: 300px;"><?php echo $post['content'] ?></textarea>
        </div>
        <div>
            <input type="submit" name="action" value="保存" /><a href="index.php" style="margin-left: 10px;">返回管理主页</a>
        </div>
    </form>
</body>
</html>
